package com.myspring.web.collection;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * 集合注入测试
 * 参考地址：https://stackoverflow.com/questions/13913752/spring-cant-autowire-map-bean
 *
 * @author : zenghua
 * @version : v0.1 CollectionController.java
 * @since : 2017/8/4 11:32
 */
@Controller
@RequestMapping("/collection")
public class CollectionController {

	//参考：https://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-autowired-annotation-qualifiers
	// https://stackoverflow.com/questions/13913752/spring-cant-autowire-map-bean
	//Autowired注解是针对类型注入，如要要别名注入要使用，参考
//	@Resource

	private HashMap<ServiceType, CollectionService> routeMap;

//	@Autowired
//	@Qualifier("route2Map")

//	@Resource
	private HashMap<String, String> route2Map;

	@RequestMapping(value = "/route")
	@ResponseBody
	public CollectionService route(String code) {
		System.out.println(routeMap);
		CollectionService collectionService = routeMap.get(ServiceType.getType(code));
		return collectionService;
	}
}
